#!/bin/bash
#password_set
read -p "please input you set password name:" u_name
id ${u_name} &>/dev/null
if [[ $? == 0 ]];then
	read -p "please input you need password(1 times):" u_pwd1
	read -p "please input you need password(2 times):" u_pwd2
	if [[ $pwd1 == $pwd2 ]];then 
		length=`echo $u_pwd2 | egrep "[0-9]" |grep "[a-Z]" |wc -l`  
		if (( ${#u_pwd2} >= 8 )) && [[ $length -gt 0 ]];then 		
			echo "${u_pwd2}" |passwd ${u_name} --stdin &>/dev/null
			echo -e "\e[1;42m set ${u_name} password success\e[0m"
		elif [[ -z $u_pwd2 ]];then
                	echo -e "\e[1;41m The password cannot be empty\e[0m" 
		
		elif [[ $length -ne 0 ]];then
			echo " the paasword nust include charactor digit"

		else
			echo "The password is less than 8 digit"
		fi
	else
		echo "The two input passwords do not match"
	fi
else
	echo "${u_name} not exists"
fi
